package Eyjafjalla.card;

import Eyjafjalla.helper.StringHelper;
import Eyjafjalla.modcore.ColorEnum;
import Eyjafjalla.patch.CloudPatch;
import Eyjafjalla.patch.FirePatch;
import Eyjafjalla.power.FireMarkPower;
import basemod.abstracts.CustomCard;
import basemod.abstracts.DynamicVariable;
import com.badlogic.gdx.graphics.Color;
import com.megacrit.cardcrawl.actions.common.ApplyPowerAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import org.omg.CORBA.PUBLIC_MEMBER;

public abstract class AbstractEyjafjallaCard extends CustomCard {

    public boolean isDolly = false;

    public boolean isFireModified;
    public boolean upgradedFire;
    public int baseFire = 0;
    public int fire = 0;

    public AbstractEyjafjallaCard(String id,String name,int cost, String rawDescription,CardType type,CardRarity rarity,CardTarget target){
        super(id,name, StringHelper.getCardIMGPatch(id,type),cost,rawDescription,type, ColorEnum.Eyjafjalla_COLOR,rarity,target);
    }

    public AbstractEyjafjallaCard(String id,String name,int cost, String rawDescription,CardType type,CardColor color,CardRarity rarity,CardTarget target){
        super(id,name, StringHelper.getCardIMGPatch(id,type,color),cost,rawDescription,type,color,rarity,target);
    }

    public AbstractEyjafjallaCard(boolean tmp,String id,String name,int cost, String rawDescription,CardType type,CardRarity rarity,CardTarget target){
        super(id,name,StringHelper.getCardIMGPatchTemp(type),cost,rawDescription,type,ColorEnum.Eyjafjalla_COLOR,rarity,target);
    }

    public void setDolly(){
        this.isDolly = true;
        this.isEthereal = true;
        this.exhaust = true;
    }

    public boolean inCloud(){
        return CloudPatch.CloudField.inCloud.get(this);
    }

    public boolean isFire(){
        return CloudPatch.CloudField.isFire.get(this)|| FirePatch.hasFireMark;
    }

    public boolean ignoreMelodyType(){
        return false;
    }

    public AbstractCard removeCardWhenObtained(){
        return null;
    }

    public void setFireDescription(String fire){
        CloudPatch.CloudField.fireDescription.set(this,fire);
        FirePatch.initializeFireDescription(this);
        CloudPatch.CloudField.showFire.set(this,true);
    }

    @Override
    public void triggerOnExhaust() {
        super.triggerOnExhaust();
        if(isDolly){
            addToBot(new ApplyPowerAction(AbstractDungeon.player,AbstractDungeon.player,new FireMarkPower(AbstractDungeon.player,1),1));
        }
    }

    @Override
    public void triggerOnGlowCheck() {
        if(isDolly){
            this.glowColor = AbstractCard.BLUE_BORDER_GLOW_COLOR.cpy();
            if(isFire()){
                this.glowColor = Color.PURPLE.cpy();
            }
        }
    }


    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {

    }

    public void upgradeFire(int num){
        baseFire += num;
        fire = baseFire;
        upgradedFire = true;
    }

    @Override
    public AbstractCard makeStatEquivalentCopy() {
        AbstractEyjafjallaCard c = (AbstractEyjafjallaCard) super.makeStatEquivalentCopy();
        c.baseFire = baseFire;
        c.fire = fire;
        c.upgradedFire = upgradedFire;
        c.isFireModified = isFireModified;
        c.magicNumber = c.baseMagicNumber;
        return c;
    }



    public static class FireNumber extends DynamicVariable{

        public FireNumber(){

        }

        @Override
        public String key(){
            return "eyjafjalla:F";
        }

        @Override
        public boolean isModified(AbstractCard abstractCard) {
            if(abstractCard instanceof AbstractEyjafjallaCard)
                return ((AbstractEyjafjallaCard)abstractCard).isFireModified;
            return false;
        }

        @Override
        public void setIsModified(AbstractCard card, boolean v) {
            if(card instanceof AbstractEyjafjallaCard){
                ((AbstractEyjafjallaCard)card).isFireModified = v;
            }
        }

        @Override
        public int value(AbstractCard abstractCard) {
            if(abstractCard instanceof AbstractEyjafjallaCard){
                return ((AbstractEyjafjallaCard)abstractCard).fire;
            }
            return -1;
        }

        @Override
        public int baseValue(AbstractCard abstractCard) {
            if(abstractCard instanceof AbstractEyjafjallaCard){
                return ((AbstractEyjafjallaCard)abstractCard).baseFire;
            }
            return -1;
        }

        @Override
        public boolean upgraded(AbstractCard abstractCard) {
            if(abstractCard instanceof AbstractEyjafjallaCard){
                return ((AbstractEyjafjallaCard)abstractCard).upgradedFire;
            }
            return false;
        }
    }
}
